<?php 
	include("library/vars.php");
	include("library/header.php"); 
?>
				
<div id="main">

<?php
	include("library/config.php");
	include("library/opendb.php");
	
	if ($show == "all") {
		$query="SELECT show_ID, season_ID, episode, title, description, seen, subs FROM episodes WHERE seen='0' ORDER BY show_ID,season_ID,(episode+0)";
		$result = mysql_query($query);
		$num=mysql_numrows($result);
	}
	else {
		$query="SELECT show_ID, season_ID, episode, title, description, seen, subs FROM episodes WHERE seen='0' AND show_ID='$show' ORDER BY show_ID,season_ID,(episode+0)";
		$result = mysql_query($query);
		$num=mysql_numrows($result);
	}
	
	echo '<div id="seasons">
		<h2>'._("All Unseen Episodes").':</h2>
	</div>';
	
	
	
	if ($num > 0) {
		echo '<h2 id="unseen_title">'._("You have").' <strong>' . $num . '</strong> '._("unseen episodes").':</h2>';
		echo '<div id="show2">
				<div class="info"><p>'._("This is the list of all your unseen episodes").'.</p></div>
			</div>
	
			<div id="unseen_episode_list">';
	
			$oddrow = 'odd';
			while(list($show_id,$season_id,$episode_nr,$title,$description,$seen,$subs)= mysql_fetch_row($result)) {
		
				$query2="SELECT show_name FROM shows WHERE show_nicename='$show_id'";
				$result2 = mysql_query($query2);
				$show_name=mysql_result($result2,$i,"show_name");
		
				$query3="SELECT season FROM seasons WHERE season='$season_id'";
				$result3 = mysql_query($query3);
				$season_name=mysql_result($result3,$i,"season");

				echo '<dl class="' ,$oddrow, '';
				if ($episode == $episode_nr) { // Change class is episode is selected
					echo ' selected ';
				}
				else {
					echo ' ep ';
				}
				echo '">';
		
				echo '<dt><span class="show_name';
					if ($seen == "0") { // Check to see if episode is unseen...
						echo ' unseen';
					}
				echo '">' . $show_name . '</span> <span class="season_nr">'._("Season").' ' . $season_name . '</span> <span class="nr">' . $episode_nr . '</span> <span class="title">' . $title . '</span> <span class="';
		
				if ($subs == "1") { // Check to see if episode has subtitles...
					echo 'subsok';
				}
				else {
					echo 'subsno';
				}
				echo '">&nbsp;</span></dt>
					<dd><p>' . $description . '</p>	
					<div class="options">
						<p class="left">';
						if ($seen == "0") {
							echo '<span><a href="mark_seen2.php?s=' . $show_id . '&amp;t=' . $season_name . '&amp;e=' . $episode_nr . '">'._("Mark as Seen").'</a></span>';
						}
						else {
							echo '<span><a href="mark_unseen2.php?s=' . $show_id . '&amp;t=' . $season_name . '&amp;e=' . $episode_nr . '">'._("Mark as Unseen").'</a></span> ';
						}
				
						if ($subs == "1") {
							echo ' <span><a href="remove_subs2.php?s=' . $show_id . '&amp;t=' . $season_name . '&amp;e=' . $episode_nr . '">'._("Remove Subtitles").'</a></span>';
						}
						else {
							echo ' <span><a href="add_subs2.php?s=' . $show_id . '&amp;t=' . $season_name . '&amp;e=' . $episode_nr . '">'._("Add Subtitles").'</a></span>';
						}
						echo '</p>
						<p class="right"><a class="edit" href="edit_episode.php?s=' . $show_id . '&amp;t=' . $season_name . '&amp;e=' . $episode_nr . '">'._("Edit").'</a> | <a class="delete delete_episode" href="delete_episode.php?s=' . $show_id . '&amp;t=' . $season_name . '&amp;e=' . $episode_nr . '">'._("Delete").'</a></p></div></dd>';
	
					echo '</dl>';
	
					if ('odd' == $oddrow) $oddrow = 'even';
					else $oddrow = 'odd';
				}
	
				echo '</div>';
			}
		else {
			echo '<div class="all_seen">'._("You have no unseen episodes.").'<br />'._("Maybe it's a good time to read a book :-)").'</div>';
		}

	mysql_free_result($result);
	include("library/closedb.php");
	
?>

	<div class="push"></div>
	
</div><!-- /main -->
<?php include("library/footer.php");?>
</body>
</html>